﻿$(document).ready(function () {
    GetChartData();
});

function GetChartData(value) {
    var store;
    var params = "{}";
    $.ajax({
        type: "POST",
        url: "barchart.aspx/GetChartData",
        data: params,
        async: false,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            store = eval(msg.d);
            ShowChart(store);
        }
    });
}
function ShowChart(store) {
    var dataPie = "[";
    var categoryPie = "[";
    for (var i = 0; i < store.length; i++) {
        categoryPie = categoryPie + "'" + store[i].Type + "',";
        dataPie = dataPie + store[i].Percentage + ",";
    }
    dataPie = dataPie.substring(0, dataPie.length - 1);
    dataPie = dataPie + "]";
    categoryPie = categoryPie.substring(0, categoryPie.length - 1);
    categoryPie = categoryPie + "]";

    chart = new window.Highcharts.Chart({
        chart: {
            type: 'bar',
            renderTo: 'divBarChart'
        },
        title: {
            text: 'Response By Gender'
        },
        subtitle: {
        //                        text: 'Source: Wikipedia.org'
    },
    xAxis: {
        categories: eval(categoryPie),
        title: {
            text: null
        }
    },
    colors: ['#8e0007', '#000000'],
    yAxis: {
        min: 0,
        title: {
            text: 'Population (millions)',
            align: 'high'
        },
        labels: {
            overflow: 'justify'
        }
    },
    tooltip: {
        valueSuffix: ' millions'
    },
    plotOptions: {
        bar: {
            dataLabels: {
                enabled: false
            }
        }
    },
    legend: {
        enable: false,
        layout: 'vertical',
        align: 'right',
        verticalAlign: 'top',
        x: -100,
        y: 100,
        floating: true,
        borderWidth: 1,
        backgroundColor: '#FFFFFF',
        shadow: true
    },
    credits: {
        enabled: false
    },
    series: [
        {
            name: 'Total Responders',
            data: eval(dataPie)
        }, {
            name: 'Total Contacts',
            data: eval(dataPie)
        }]
});
}

//$(document).ready(function () {
//    $('#barChart').highcharts({
//        chart: {
//            type: 'bar'
//        },
//        title: {
//            text: 'Response By Geography'
//        },
//        subtitle: {
//        //                        text: 'Source: Wikipedia.org'
//    },
//    xAxis: {
//        categories: ['US Armed Forces', 'New England', 'Mid West', 'Mid Atlantic', 'West', 'Internationa', 'South', 'South West'],
//        title: {
//            text: null
//        }
//    },
//    colors: ['#8e0007', '#000000'],
//    yAxis: {
//        min: 0,
//        title: {
//            text: 'Population (millions)',
//            align: 'high'
//        },
//        labels: {
//            overflow: 'justify'
//        }
//    },
//    tooltip: {
//        valueSuffix: ' millions'
//    },
//    plotOptions: {
//        bar: {
//            dataLabels: {
//                enabled: false
//            }
//        }
//    },
//    legend: {
//        enable: false,
//        layout: 'vertical',
//        align: 'right',
//        verticalAlign: 'top',
//        x: -100,
//        y: 100,
//        floating: true,
//        borderWidth: 1,
//        backgroundColor: '#FFFFFF',
//        shadow: true
//    },
//    credits: {
//        enabled: false
//    },
//    series: [{
//        data: [5, 10, 15, 20, 25, 30, 35, 40]
//    }, {
//        data: [5, 10, 15, 20, 25, 30, 35, 40]
//    }]
//});
//});